//
//  ViewController.m
//  字典
//
//  Created by clz on 2019/7/14.
//  Copyright © 2019年 clz. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //不可变字典
    NSDictionary *dic = [[NSDictionary alloc]init];
    NSDictionary *dic1 = [NSDictionary dictionaryWithObject:@"value01" forKey:@"key01"];
    /*
     {
        @"key":@"value",
        @"key2":@"value2"
     }
     
     */
    NSDictionary *dic2 = @{
                            @"name":@"xiaoming",
                            @"age":@"11"
                           };
    NSDictionary *dic3 = [NSDictionary dictionaryWithDictionary:dic2];
//    NSLog(@"dic3 = %@",dic3);
    NSDictionary *dic4 = [NSDictionary dictionaryWithObjectsAndKeys:@"name",@"xiaoming",@"age",@"11", nil];
    //可变字典
    NSMutableDictionary *dic5 = [[NSMutableDictionary alloc]init];
//    NSMutableDictionary *dic6 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"name",@"xiaoming",@"age",@"11", nil];
//    NSMutableDictionary *dic7 = [NSMutableDictionary dictionaryWithDictionary:dic2];
    
    //操作可变字典
    //添加
    [dic5 setObject:@"xiaoming" forKey:@"name"];
    [dic5 setObject:@"12" forKey:@"age"];
    [dic5 setObject:@"170" forKey:@"height"];
    //修改
    [dic5 setObject:@"xiaofang" forKey:@"name"];
    //删除
//    [dic5 removeObjectForKey:@"name"];
//    [dic5 removeAllObjects];
    
    
    
//    NSLog(@"dic5 = %@",dic5);
    //获取所有的key
    NSArray *array = [dic5 allKeys];
//    NSLog(@"array = %@",array);
    //遍历
    for (id key in dic5) {
        NSLog(@"key:%@ value:%@",key,[dic5 objectForKey:key]);//通过key 来获取value
    }

    
}


@end
